/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>Project: jse2306 - Ex2</p>
 * <p>Powered by webrx On 2023-10-10 11:41:15</p>
 * <p>description: </p>
 *
 * @author 李四 [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex5 {
    public static void main(String[] args) throws ParseException {

        //2 建立指定日期对象
        Date ss = new Date(2000 - 1900, 2 - 1, 1, 8, 20, 30);
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", ss);

        Date now = new Date(); //当前日期
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", now);

        //7天前
        Date d7 = new Date(now.getTime() - (1000 * 60 * 60 * 24 * 7));
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", d7);

        //5天后 1 24 60 60s 1000 1000
        var d5 = new Date(now.getTime() + (1000 * 60 * 60 * 24 * 5));
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", d5);

        //4 计算生活多少天 1988-9-5 8:0:0 到 now 12819天
        Date birth = new Date(1988 - 1900, 9 - 1, 5, 8, 0, 0);
        long ms = System.currentTimeMillis() - birth.getTime();
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", birth);
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", System.currentTimeMillis());
        System.out.println(ms / (1000 * 60 * 60 * 24));


        System.exit(0);
        //Locale.setDefault(Locale.US);
        //1 输入日期格式 yyyy-MM-dd HH:mm:ss 星期几 几月 上午
        System.out.println("--------------------------格式化系统当前日期");
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", new Date());

        var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss EEEE MMMMM aaa");
        String info = sdf.format(new Date());
        System.out.println(info);

        //格式化指定日期
        System.out.println("--------------------------格式化指定日期");
        var s2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String ts = "2001-9-11 10:20:30";
        Date d2 = s2.parse(ts);
        System.out.println(sdf.format(d2));
        System.out.printf("%tF %<tT %<tA %<tB %<tp%n", d2);
        var s3 = new SimpleDateFormat("MM月dd日");
        System.out.println(s3.format(d2));

    }
}
